<template>
	<view class="score">
		<uni-nav-bar left-icon="back" backgroundColor="#007AFF" color="#fff" statusBar fixed :border="false"
			title="我的积分" @clickLeft="clickLeft"></uni-nav-bar>
		<view class="box">
			<view class="num">
				<text>110</text>
			</view>
			<view class="">
				<unicloud-db v-slot:default="{data, loading, error, options}" collection="uni-id-scores"
					where="'user_id' == $env.uid">
					<view v-if="error">{{error.message}}</view>
					<view v-else>
						<view class="" v-for="item in data" :key="item._id">
							{{ item.score }}
						</view>
					</view>
				</unicloud-db>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current:0,
			}
		},
		methods: {
			clickLeft() {
				uni.navigateBack({
					delta: 1
				})
			},
			init() {
				db.collection("uni-id-scores")
					.where('"user_id" == $env.uid')
					.field('score,balance')
					.orderBy("create_date", "desc")
					.limit(1)
					.get()
					.then((res) => {
						console.log(res);
						const data = res.result.data[0];
						let msg = '';
						msg = data ? (this.$t('mine.currentScore') + data.balance) : this.$t('mine.noScore');
						uni.showToast({
							title: msg,
							icon: 'none'
						});
					}).finally(() => {
						uni.hideLoading()
					})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.score {
		.box {
			box-sizing: border-box;
			.num {
				width: 100%;
				height: 200rpx;
				background-image: linear-gradient(#007AFF, #0057b5);
				overflow: hidden;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #FFFFFF;
				font-size: 44rpx;
				border-radius: 0 0 30rpx 30rpx;
			}
		}
	}
</style>
